package cn.sofwin.day0202.homework;

import static java.lang.Math.min;

public class Employee implements Comparable<Employee>{
    private String name;
    private int age;
    private MyDate birthday;

    public Employee() {
    }

    public Employee(String name, int age, MyDate birthday) {
        this.name = name;
        this.age = age;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "[姓名：" + name
                + "，年龄：" + age
                + "，出生日期：" + birthday.getYear()
                + "-" + birthday.getMonth()
                + "-" + birthday.getDay() + "]";
    }

    @Override
    public int compareTo(Employee o) {
        if (getName().equals(o.getName())){
            return 0;
        }

        int minLenth = min(getName().length(), o.getName().length());
        for (int i = 0; i < minLenth; i++) {
            if (getName().charAt(i) != o.getName().charAt(i)){
                return getName().charAt(i) - o.getName().charAt(i);
            }
        }

        return getName().length() > o.getName().length() ? 1 : -1;
    }
}
